package learn.service.impl;

import learn.dao.UserMapper;
import learn.domain.User;
import learn.domain.UserExample;
import learn.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by sqluogui on 2016/9/13.
 */
@Service
public class UserServiceImpl implements UserService {
    private static Logger logger = Logger.getLogger(String.valueOf(UserServiceImpl.class));
    @Autowired
    UserMapper userMapper;

    @Override
    public User queryUserById(int id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> queryAllUser() {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andIdGreaterThan(0);
        return userMapper.selectByExample(userExample);
    }

    @Override
    public User queryByNamePwd(String userName,String pwd){
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUserNameEqualTo(userName);
        criteria.andPassWordEqualTo(pwd);
        List<User> userList = userMapper.selectByExample(userExample);
        if(userExample!=null && userList.size()>0){
            return userList.get(0);
        }
        return null;
    }
}
